﻿@using AdverseEventReportSystem.BLL.SchedulingSystem
@{
    var signIn = ViewBag.SignIn as SchedulingSignIn;
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Edit</title>
    <link href="~/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
    <link href="~/lib/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
    <link href="~/lib/ligerUI/skins/Gray/css/all.css" rel="stylesheet" type="text/css" />
    <link href="~/Content/css/common.css" rel="stylesheet" type="text/css" />
    <script src="~/lib/jquery/jquery-1.9.0.min.js" type="text/javascript"></script>
    <script src="~/lib/ligerUI/js/ligerui.all.js"></script>
    <script src="~/Scripts/common.js"></script>
    <style>
        .gridtable {
            width: 100%;
            margin: 0px;
        }

            .gridtable td {
                height: 30px;
                line-height: 30px;
            }
    </style>
</head>
<body>
    <div style="margin:10px 0px;">
        <table class="gridtable">
            <tr>
                <td style="text-align:right; width:80px;">
                    日期：
                </td>
                <td>
                    <label id="lblSignInDate">@(AdverseEventReportSystem.Utils.DataConvert.StrToDateTime(signIn.SignInDate, DateTime.Now).ToString("yyyy-MM-dd"))</label>
                </td>
            </tr>
            <tr>
                <td style="text-align:right; width:80px;">
                    班别：
                </td>
                <td>
                    <input type="text" id="schedulingCategory">
                </td>
            </tr>
            <tr>
                <td colspan="2" style="text-align:center;padding-top:10px;">
                    <input id="btnSubmit" type="button" value="确定" class="l-button" onclick="save()" />&nbsp;&nbsp;&nbsp;
                    <input id="btnCancel" type="button" value="取消" class="l-button-cancel" onclick="closeDialog()" />
                </td>
            </tr>
            <tr></tr>
        </table>
    </div>
    <input type="hidden" id="hdnSignInId" value="@(signIn.Id)" />
    <input type="hidden" id="hdnCategoryId" value="@(signIn.CategoryId)" />
    <input type="hidden" id="hdnOldCategoryId" value="@(signIn.OldCategoryId)" />
</body>
</html>
<script>
    var comboBox;
    var firstLoading = true;

    $(function () {
        comboBox = $("#schedulingCategory").ligerComboBox({
            width: 280,
            slide: false,
            selectBoxWidth: 280,
            selectBoxHeight: 200,
            valueField: 'Id',
            textField: 'Code',
            delayLoadGrid: false,
            grid: {
                url: "/Scheduling/SchedulingSignIn/GetSchedulingCategoryList",
                columns: [
                    { display: '班别', name: 'Code', align: 'left', width: 100, minWidth: 60 }
                ],
                usePager: false,
                rownumbers: false,
                enabledSort: false,
                checkbox: true,
                onAfterShowData: function (data) {
                    if (firstLoading) {
                        var index = 0;
                        var setCategoryId = "";
                        var list = [];
                        if ($("#hdnSignInId").val() == 0) {
                            setCategoryId = "|" + $("#hdnOldCategoryId").val() + "|";
                        }
                        else {
                            setCategoryId = "|" + $("#hdnCategoryId").val() + "|";
                        }
                        $('.l-grid2').find(".l-grid-row-cell-inner").each(function () {
                            var _index = setCategoryId.indexOf("|" + data.Rows[index].Id + "|");
                            if (_index != -1) {
                                list.splice(_index, 0, $(this));
                            }
                            index++;
                        });
                        for (var i = 0; i < list.length; i++) {
                            list[i].click();
                        }
                    }
                    $("#schedulingCategory").blur();
                    firstLoading = false;
                }
            },
            condition: { fields: [{ name: 'Code', label: '<font style="margin-left:15px;">班别</font>', width: 90, type: 'text' }] },
            conditionSearchClick: function (e) {
                e.grid.set('parms', { code: e.rules.length > 0 ? e.rules[0].value : "" });
                e.grid.reload();
            }
        });
    });

    function save() {
        var categoryId = "";
        var categoryCode = "";
        var categoryColor = "";
        var selected = comboBox.getSelected();
        if (selected != undefined) {
            for (var i = 0; i < selected.length; i++) {
                categoryId += selected[i].Id + "|";
                categoryCode += selected[i].Code + "|";
                categoryColor += selected[i].Color + "|";
            }
            categoryId = categoryId.substring(0, categoryId.length - 1);
            categoryCode = categoryCode.substring(0, categoryCode.length - 1);
            categoryColor = categoryColor.substring(0, categoryColor.length - 1);
        }
       
        var dialog = frameElement.dialog;
        $.ajax({
            url: "/Scheduling/SchedulingSignIn/Save",
            type: "post",
            data: {
                Id: $("#hdnSignInId").val(),
                SignInDate: $("#lblSignInDate").text(),
                CategoryId: categoryId,
                CategoryCode: categoryCode,
                CategoryColor: categoryColor
            },
            success: function (r) {
                var r = $.parseJSON(r);
                if (r.Result == 1) {
                    parent.$(".l-dialog-btn-inner").click();
                    dialog.close();
                }
                else if (r.Result == 0) {
                    $.ligerDialog.error(r.Body);
                }
                else {
                    $.ligerDialog.error("程序错误");
                }
            },
            error: function () {
                $.ligerDialog.error("程序错误");
            }
        });
    }

    function closeDialog() {
        frameElement.dialog.close();//关闭dialog
    }
</script>
